package com.chatroomdemo.controller;

import com.chatroomdemo.model.Message;
import com.chatroomdemo.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /**
     * @author 陈嘉宇
     *
     * @param sessionId
     * @param sessionId
     * @return List<Message> 获取历史消息
     */
    @RequestMapping("/getMessageRecordBySessionId")
    public List<Message> getMessageRecordBySessionId(Integer sessionId) throws Exception {
        if(sessionId == null || sessionId < 0){
            log.info("获取参数 sessionId:" + sessionId);
            throw new Exception("sessionId 不合法");
        }
        return messageService.getMessageRecordBySessionId(sessionId);
    }
}
